package com.ruoyi.appService.CollegeStudentsTestList.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;

import com.ruoyi.appService.CollegeStudentsTestList.mapper.ZuserHealthTestListRelation;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.framework.web.service.WxTokenService;
import com.ruoyi.framework.web.service.wxUserRedis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.appService.CollegeStudentsTestList.mapper.ZMentalHealthTestListMapper;
import com.ruoyi.appService.CollegeStudentsTestList.domain.ZMentalHealthTestList;
import com.ruoyi.appService.CollegeStudentsTestList.service.IZMentalHealthTestListService;

import javax.servlet.http.HttpServletRequest;

/**
 * 大学生心理健康测试列表Service业务层处理
 *
 * @author ç¹è½æ²
 * @date 2025-05-16
 */
@Service
public class ZMentalHealthTestListServiceImpl extends ServiceImpl<ZMentalHealthTestListMapper, ZMentalHealthTestList> implements IZMentalHealthTestListService {
    @Autowired
    private ZMentalHealthTestListMapper zMentalHealthTestListMapper;
    @Autowired
    private ZuserHealthTestListRelation zuserHealthTestListRelation;
    @Autowired
    private WxTokenService wxTokenService;

    /**
     * 查询大学生心理健康测试列表
     *
     * @param id 大学生心理健康测试列表主键
     * @return 大学生心理健康测试列表
     */
    @Override
    public ZMentalHealthTestList selectZMentalHealthTestListById(Long id) {
        return zMentalHealthTestListMapper.selectZMentalHealthTestListById(id);
    }

    /**
     * 查询大学生心理健康测试列表列表
     *
     * @param zMentalHealthTestList 大学生心理健康测试列表
     * @return 大学生心理健康测试列表
     */
    @Override
    public List<ZMentalHealthTestList> selectZMentalHealthTestListList(ZMentalHealthTestList zMentalHealthTestList) {
        return zMentalHealthTestListMapper.selectZMentalHealthTestListList(zMentalHealthTestList);
    }

    /**
     * 新增大学生心理健康测试列表
     *
     * @param zMentalHealthTestList 大学生心理健康测试列表
     * @return 结果
     */
    @Override
    public int insertZMentalHealthTestList(ZMentalHealthTestList zMentalHealthTestList) {
                zMentalHealthTestList.setCreateTime(DateUtils.getNowDate());
            return zMentalHealthTestListMapper.insertZMentalHealthTestList(zMentalHealthTestList);
    }

    /**
     * 修改大学生心理健康测试列表
     *
     * @param zMentalHealthTestList 大学生心理健康测试列表
     * @return 结果
     */
    @Override
    public int updateZMentalHealthTestList(ZMentalHealthTestList zMentalHealthTestList) {
        return zMentalHealthTestListMapper.updateZMentalHealthTestList(zMentalHealthTestList);
    }

    /**
     * 批量删除大学生心理健康测试列表
     *
     * @param ids 需要删除的大学生心理健康测试列表主键
     * @return 结果
     */
    @Override
    public int deleteZMentalHealthTestListByIds(Long[] ids) {
        return zMentalHealthTestListMapper.deleteZMentalHealthTestListByIds(ids);
    }

    /**
     * 删除大学生心理健康测试列表信息
     *
     * @param id 大学生心理健康测试列表主键
     * @return 结果
     */
    @Override
    public int deleteZMentalHealthTestListById(Long id) {
        return zMentalHealthTestListMapper.deleteZMentalHealthTestListById(id);
    }

    @Override
    public int[] selectCompletedTestList(HttpServletRequest request) {
        //从请求头中获取token
        String token = wxTokenService.getToken(request);
        //解析得到token得到键，想redis中查找对应的值，并返回
        wxUserRedis wxuserRedis = wxTokenService.getwxUser(token);
        int userId=wxuserRedis.getUserId();

        return zuserHealthTestListRelation.selectCompletedTestList(userId) ;
    }

    @Override
    public void insertCompletedTestList(int testId, HttpServletRequest request) {
        //从请求头中获取token
        String token = wxTokenService.getToken(request);
        //解析得到token得到键，想redis中查找对应的值，并返回
        wxUserRedis wxuserRedis = wxTokenService.getwxUser(token);
        int userId=wxuserRedis.getUserId();

        zuserHealthTestListRelation.insertCompletedTestList(userId,testId);


    }
}